package com.zls.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zls.pojo.ProductBatches;
import com.zls.pojo.SysUser;
import com.zls.pojo.TFarm;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface ProductBatchesMapper extends BaseMapper<ProductBatches> {
    @Results(id = "proMap", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "product_name", property = "productName"),
            @Result(column = "isactive", property = "isactive"),
            @Result(column = "product_batch", property = "productBatch"),
            @Result(column = "area", property = "area"),
            @Result(column = "recoverydate", property = "recoverydate"),
            @Result(column = "img", property = "img"),
            @Result(column = "feature", property = "feature"),
            @Result(column = "sys_user_id", property = "sysUserId"),
            @Result(column = "farm_id", property = "farmId"),
            @Result(column = "farm_id", property = "tFarm", javaType = TFarm.class, one =
            @One(select = "com.zls.mapper.TFarmMapper.selectId", fetchType = FetchType.EAGER))
    })
    @Select("<script>" +
            "select * from product_batches where 1 =1" +
            "<if test='queryString!=null'> and product_name like concat( '%',#{queryString},'%')" +
            "limit #{currentPage},#{pageSize}</if>" +
            "<if test='queryString==null'>limit #{currentPage},#{pageSize}</if> "+
            "</script>")
    List<ProductBatches> findPage(@Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize, @Param("queryString") String queryString);

    //查询总记录数
    @Select("<script>" +
            "select count(*) from product_batches where 1 =1" +
            "<if test='queryString!=null'> and product_name like concat( '%',#{queryString},'%') </if>" +
            "</script>")
    Long count(String queryString);


    @Select("select * from product_batches where id=#{id}")
    ProductBatches selectById(Integer id);

    @Select("select * from product_batches where product_batch=#{productBatch}")
    ProductBatches selectByBatch(String productBatch);
}
